package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.PatronLevelArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

public class PatronLevelFundCondition extends BaseActivityCondition {

    public PatronLevelFundCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        PatronLevelArgs args = (PatronLevelArgs) object;
        if (activityConditionInfo.getParamList().get(1).intValue() == args.getPatronId()) {
            setValue(BigInteger.valueOf(args.getLevel()));
        }
    }

    public boolean isCompleted(GamePlayer player) {
        //第一位是是否要購買過
        if(activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ONE) == 0){
            //是否購買了
            if(player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.PatronsLevelFund) == 1){
                return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
            }
        }else if(activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ZERO) == 0){
            return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
        }
        return false;
    }


    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.PatronsLevelFund.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.PatronsLevelFund.getValue(), handle);
    }
}
